// abnormallyReport.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    faultItems: [{
        name: '单灯不亮',
        value: '单灯不亮'
      },
      {
        name: '线路故障',
        value: '线路故障'
      },
      {
        name: '控制箱故障',
        value: '控制箱故障'
      },
      {
        name: '灯杆门缺损',
        value: '灯杆门缺损'
      },
      {
        name: '灯杆缺陷',
        value: '灯杆缺陷'
      },
      {
        name: '乱挂广告牌',
        value: '乱挂广告牌'
      },
      {
        name: '紧急突发故障',
        value: '紧急突发故障'
      },
      {
        name: '控制箱维护',
        value: '控制箱维护'
      },
      {
        name: '其他故障隐患',
        value: '其他故障隐患'
      },
    ],
    pdxItems: [{
        name: '控制箱故障',
        value: '控制箱故障'
      },
      {
        name: '控制箱维护',
        value: '控制箱维护'
      },
    ],
    lineItems: [{
        name: '线路断路、短路',
        value: '线路断路、短路'
      },
      {
        name: '线路漏电',
        value: '线路漏电'
      },
      {
        name: '软故障',
        value: '软故障'
      },
      {
        name: '线路断路、短路及线路漏电',
        value: '线路断路、短路及线路漏电'
      },
    ],
    reasonList: [{
        name: '自然老化',
        value: '自然老化'
      },
      {
        name: '外力破坏',
        value: '外力破坏'
      },
    ],
    measureList: [{
        name: '重新接驳电缆',
        value: '重新接驳电缆'
      },
      {
        name: '更换电缆',
        value: '更换电缆'
      },
      {
        name: '架空、地埋敷设电缆、电线',
        value: '架空、地埋敷设电缆、电线'
      },
      {
        name: '电缆被盗重新敷设',
        value: '电缆被盗重新敷设'
      },
    ],
    repairList: [{
        name: '调整灯具角度',
        value: '调整灯具角度'
      },
      {
        name: '更换灯具',
        value: '更换灯具'
      },
      {
        name: '更换平行线',
        value: '更换平行线'
      },
      {
        name: '补上灯杆盖',
        value: '补上灯杆盖'
      },
      {
        name: '拆除广告牌',
        value: '拆除广告牌'
      },
      {
        name: '修剪树木',
        value: '修剪树木'
      },
      {
        name: '更换时控',
        value: '更换时控'
      },
      {
        name: '更换熔芯',
        value: '更换熔芯'
      },
      {
        name: '更换终端主板',
        value: '更换终端主板'
      },
      {
        name: '更换空气开关',
        value: '更换空气开关'
      },
      {
        name: '更换交流接触器',
        value: '更换交流接触器'
      },
    ],
    tearList: [{
        name: '拆除灯杆处理',
        value: '拆除灯杆处理'
      },
      {
        name: '重立灯杆处理',
        value: '重立灯杆处理'
      },
      {
        name: '拆除重立灯杆处理',
        value: '拆除重立灯杆处理'
      },
      {
        name: '调整灯杆垂直度或支架角度',
        value: '调整灯杆垂直度或支架角度'
      },
    ],
    rushList: [{
      name: '拆除灯杆处理',
      value: '拆除灯杆处理'
    }, ],
    gzList: ['路灯不亮', '灯杆损坏倾斜', '线缆外露损坏', '灯杆门缺损', '附近成片熄灯', '其他故障'],
    tabList: [{
      title: '路灯上报',
      value: "1"
    }, {
      title: '配电箱上报',
      value: "3"
    }, {
      title: '自定义上报',
      value: "2"
    }],
    tabIndex: "1",
    faultDescription: "",
    faultLine: "",
    canRemark: false,
    str1: ['a'],
    str2: 'a',
    facilitiesNo: '', //设施编号
    streetLampType: '', //路灯类型
    address: '', //地址
    jwdInfo: '', //经纬度
    // powerUnit: '',//权属单位
    name: '',
    phone: '',
    deptid: 4, //部门id
    loading: false,
    userInfo: {},
    exlist: [],
    radioVal: '',
    exobj: {},
    moreChflag: true,
    pdxDialog: true,
    id: '',
    type: 3,
    tittleInfo: '路灯选择',
    mapshow: true,
    longitude: 113.324520,
    latitude: 23.099994,
    remark: '',
    streetLampId: '',
    hasScene: false,
    imgshow: [],
    imgUrl: [],
    deptPhone: "86881114",
    detail: {},
    gdTypeList: [{
        name: '检查线路',
        value: '检查线路'
      },
      {
        name: '检修',
        value: '检修'
      },
      {
        name: '拆立杆',
        value: '拆立杆'
      },
      {
        name: '抢修',
        value: '抢修'
      },
      {
        name: '其他',
        value: '其他'
      },
    ],
    gdType: '检查线路',
    dataSourceList: ['86881114', '12345', '95598', '交警', '住建工单', '城市交办函'],
    dataSource: '',
    treamId: '',
    liveArea: '',
    complainantUserName: '',
    complainantUserPhone: '',
    pdxlist: [],
    pdxName: '',
    radioValPdx: '',
    pdxobj: {},
    returnDate: '',
    returnTime: '',
    makeDate: '',
    makeTime: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // options 中的 scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
    var scene = options.scene ? decodeURIComponent(options.scene) : '';
    this.setData({
      navHeight: app.globalData.navHeight
    })

    if (scene != 'undefined' && scene) {
      console.log(scene)
      that.setData({
        id: scene,
        hasScene: true,
      });
    }
    this.setData({
      name: wx.getStorageSync('nickname'),
      phone: wx.getStorageSync('phone'),
    })
    this.getTeamList()
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.getUserInfo();
    var that = this;
    var scene = that.data.id;
    if (scene != '') {
      //查询故障信息
      that.searchEX(scene);
    } else {
      //需要登录系统账号信息
      // that.checkLogin();
      // wx.setNavigationBarTitle({
      //   title: wx.getStorageSync('deptName')
      // })
    }
  },
  onShareAppMessage: function () {

  },
  getUserInfo: function () {
    var that = this
    wx.getUserInfo({
      lang: 'zh_CN',
      success: function (res) {

      },
      fail: function (res) {
        wx.showModal({
          title: '需要您授权才能正常显示',
          content: '请点击“去授权”并点击授权按钮，即可正常使用',
          confirmText: '去授权',
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              // wx.openSetting({
              //   success: function (re) {
              //     if (!re.authSetting["scope.userInfo"] || !re.authSetting["scope.userLocation"]) {
              //       var isset = that.data.isSetUserInfo
              //       if(!isset){
              //         that.getUserInfo()
              //       }
              //     }else{
              //       that.setData({ isSetUserInfo : true})
              //     }
              //   }
              // })
              console.log("用户点击确定")
              wx.navigateTo({
                url: '../authorize/authorize',
              })
            }
          }
        })
      }
    })
  },
  checkLogin: function () {
    var name = wx.getStorageSync('userName')
    if (name == '' || name == null) {
      wx.showModal({
        title: '提示',
        content: "用户未登录",
        confirmText: '去登录',
        showCancel: false,
        success: function () {
          wx.navigateTo({
            url: '../login/login',
          })
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  //当获取焦点时触发
  focusFun: function (e) {
    // var that = this;
    // var param = e.target.dataset.param;
    // that.searchEXlist();
    // var val = 0;
    // var tittle = '终端编号选择';
    // if (param==1){
    //   val = 1;
    //   tittle = '终端编号选择';
    // } else if (param == 3){
    //   val = 3;
    //   tittle = '地址选择';
    // } else if (param == 4) {
    //   val = 4;
    //   tittle = '经纬度选择';
    // }
    // that.setData({type:val,tittleInfo:tittle});
  },
  //根据id查询
  searchEX: function (id) {
    var that = this;
    var header = {
      'content-type': 'application/x-www-form-urlencoded'
    };
    var param = {
      id: id
    };
    wx.request({
      url: app.url + '/web/streetLamp/getById.htm',
      data: app.ecbEncrypto(param),
      method: 'POST',
      header: header,
      success: function (res) {
        var decodingStr = app.ecbDecrypto(res.data)
        var rest = JSON.parse(decodingStr)
        console.log(rest);
        if (rest.isSuccess == 0) {
          var entity = rest.result;
          that.setData({
            facilitiesNo: entity.meterAddr, //设施编号
            streetLampType: entity.streetLampType, //路灯类型
            address: entity.address, //地址
            jwdInfo: entity.lngLat, //经纬度
            // powerUnit: entity.powerUnit,//权属单位
            deptid: entity.deptid,
            deptPhone: entity.deptPhone,
            streetLampId: id,
            detail: entity,
            liveArea: entity.liveArea
          });
          // wx.setNavigationBarTitle({
          //   title: entity.powerUnit
          // })
          console.log(entity)
        }
      }
    })
  },
  //查询集合获取终端编号
  searchEXlist: function () {
    var that = this;
    var header = {
      'content-type': 'application/x-www-form-urlencoded'
    };
    var userName = wx.getStorageSync("userName")
    let params = {
      address: this.data.address,
      userName: userName,
      pageNumber: 1,
      filter: 1,
      pageSize: 10000,
    }
    console.log(params)
    var encodingStr = app.ecbEncrypto(params);
    console.log(encodingStr)
    wx.request({
      url: app.url + '/web/streetLamp/getList.htm',
      data: encodingStr,
      method: 'POST',
      header: header,
      success: function (res) {
        var decodingStr = app.ecbDecrypto(res.data)
        var rest = JSON.parse(decodingStr)
        console.log(rest);
        if (rest.isSuccess == 0) {
          that.setData({
            exlist: rest.result.content,
            moreChflag: false
          });
        }
      }
    })
  },
  // 查询配电箱数据
  searchPdxlist: function () {
    var that = this;
    var header = {
      'content-type': 'application/x-www-form-urlencoded'
    };
    var userName = wx.getStorageSync("userName")
    let params = {
      name: this.data.pdxName,
      userName: userName,
      pageNumber: 1,
      pageSize: 10000,
    }
    console.log(params)
    var encodingStr = app.ecbEncrypto(params);
    console.log(encodingStr)
    wx.request({
      url: app.url + '/web/distridutionBox/getList.htm',
      data: encodingStr,
      method: 'POST',
      header: header,
      success: function (res) {
        var decodingStr = app.ecbDecrypto(res.data)
        var rest = JSON.parse(decodingStr)
        console.log(rest);
        if (rest.isSuccess == 0) {
          that.setData({
            pdxlist: rest.result.content,
            pdxDialog: false
          });
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //为空判断
  getValue: function (e) {
    var that = this;
    var param = e.target.dataset.param;
    var val = e.detail.value;
    if (param == 1) {
      that.setData({
        facilitiesNo: val.trim()
      });
    } else if (param == 2) {
      that.setData({
        liveArea: val.trim()
      });
    } else if (param == 3) {
      that.setData({
        address: val.trim()
      });
    } else if (param == 4) {
      that.setData({
        jwdInfo: val.trim()
      });
    }
    // else if (param == 5){
    //   that.setData({ powerUnit: val.trim() });
    // } 
    else if (param == 6) {
      that.setData({
        name: val.trim()
      });
    } else if (param == 7) {
      that.setData({
        phone: val.trim()
      });
    } else if (param == 8) {
      that.setData({
        remark: val.trim()
      });
    } else if (param == 8) {
      that.setData({
        remark: val.trim()
      });
    } else {
      var obj = {};
      obj[param] = val.trim();
      that.setData(obj);
    }
  },
  getTeamList() {
    var that = this;
    var params = {
      pageNumber: 1,
      pageSize: 10000,
      deptid: 4,
      type: 1,
    }
    var paramsCode = app.ecbEncrypto(params)
    wx.request({
      url: app.url + '/web/sysTream/getList.htm',
      data: paramsCode,
      method: 'POST',
      success: function (res) {
        var decodingStr = app.ecbDecrypto(res.data);
        var rest = JSON.parse(decodingStr)
        console.log(rest)
        if (rest.isSuccess == 0) {
          var list = rest.result.content.map(item => ({
            ...item,
            value: item.id
          }))
          that.setData({
            teamList: list
          })
        }
      },
      complete: function () {

      }
    })
  },
  bindPickerChange: function (e) {
    const {
      param,
      list
    } = e.currentTarget.dataset;
    const obj = {};
    obj[param] = this.data[list][e.detail.value]
    this.setData(obj)
  },
  checkboxChange: function (e) {
    var cboxs = e.detail.value;
    var val = cboxs[(cboxs.length || 1) - 1]?.toString();
    if (this.data.tabIndex != 3) {
      var faultItems = this.data.faultItems;
      faultItems.forEach((item, index) => {
        item.checked = val == item.value
      })
      var canRemark = cboxs.indexOf('其他故障') > -1;
      if (!canRemark) {
        this.setData({
          remark: ''
        })
      }
      this.setData({
        faultDescription: val,
        faultItems: faultItems,
        canRemark: canRemark
      });
    } else {
      const pdxItems = this.data.pdxItems
      pdxItems.forEach((item, index) => {
        item.checked = val == item.value
      })
      this.setData({
        pdxItems
      })
    }
  },
  checkboxChangeCom(e) {
    const {
      listname,
      listkey
    } = e.currentTarget.dataset;
    var cboxs = e.detail.value;
    var faultItems = this.data[listname];

    console.log(faultItems)
    faultItems.forEach((item, index) => {
      item.checked = cboxs == item.value
    })
    const obj = {};
    obj[listname] = faultItems;
    obj[listkey] = cboxs.toString();
    console.log(obj);
    this.setData(obj);
    console.log(e)
  },
  checklineChange: function (e) {
    var cboxs = e.detail.value;
    var faultItems = this.data.lineItems;
    var val = cboxs.toString();
    faultItems.forEach((item, index) => {
      item.checked = cboxs.indexOf(item.value) > -1
    })
    this.setData({
      faultLine: val,
      lineItems: faultItems
    });
  },
  checkReasonChange: function (e) {
    var cboxs = e.detail.value;
    var faultItems = this.data.reasonList;
    var val = cboxs.toString();
    faultItems.forEach((item, index) => {
      item.checked = cboxs.indexOf(item.value) > -1
    })
    this.setData({
      faultLine: val,
      reasonList: faultItems
    });
  },
  checkMeasureChange: function (e) {
    var cboxs = e.detail.value;
    var faultItems = this.data.measureList;
    var val = cboxs.toString();
    faultItems.forEach((item, index) => {
      item.checked = cboxs.indexOf(item.value) > -1
    })
    this.setData({
      faultLine: val,
      measureList: faultItems,
    });
  },
  checkRepairChange: function (e) {
    var cboxs = e.detail.value;
    var faultItems = this.data.repairList;
    var val = cboxs.toString();
    faultItems.forEach((item, index) => {
      item.checked = cboxs.indexOf(item.value) > -1
    })
    this.setData({
      faultLine: val,
      repairList: faultItems,
    });
  },
  checkTearChange: function (e) {
    var cboxs = e.detail.value;
    var faultItems = this.data.tearList;
    var val = cboxs.toString();
    faultItems.forEach((item, index) => {
      item.checked = cboxs.indexOf(item.value) > -1
    })
    this.setData({
      faultLine: val,
      tearList: faultItems,
    });
  },
  checkRushChange: function (e) {
    var cboxs = e.detail.value;
    var faultItems = this.data.rushList;
    var val = cboxs.toString();
    faultItems.forEach((item, index) => {
      item.checked = cboxs.indexOf(item.value) > -1
    })
    this.setData({
      faultLine: val,
      rushList: faultItems,
    });
  },
  //工单类别选择
  checkGdType(e) {
    const cboxs = e.detail.value;
    console.log(cboxs);
    this.setData({
      gdType: cboxs
    });
  },
  exsubmit: function () {



    var that = this;
    var faultDescription = that.data.faultDescription;
    var facilitiesNo = that.data.facilitiesNo;
    var streetLampType = that.data.streetLampType;
    var address = that.data.address;
    var jwdInfo = that.data.jwdInfo;
    // var powerUnit = that.data.powerUnit;
    var name = that.data.name;
    var phone = that.data.phone;
    var remark = that.data.remark;
    var reportType = that.data.tabIndex;
    var treamId = that.data.treamId;
    var dataSource = that.data.dataSource;
    const {
      complainantUserPhone,
      complainantUserName,
      pdxName,
      pdxobj
    } = this.data;


    // if (facilitiesNo == '') {
    //   wx.showToast({
    //     title: '设施编号不能为空',
    //     image: '../../images/error.png',
    //     duration: 2000,
    //     mask: true
    //   })
    //   return false;
    // }
    if (streetLampType == '' && reportType == 1) {
      wx.showToast({
        title: '路灯类型不能为空',
        image: '../../images/error.png',
        duration: 2000,
        mask: true
      })
      return false;
    }
    if (!pdxName && reportType == 3) {
      wx.showToast({
        title: '配电箱不能为空',
        image: '../../images/error.png',
        duration: 2000,
        mask: true
      })
      return false;
    }

    if (address == '' && reportType == 1) {
      wx.showToast({
        title: '地址不能为空',
        image: '../../images/error.png',
        duration: 2000,
        mask: true
      })
      return false;
    }

   

    if (jwdInfo == '' && (reportType == 1 || reportType == 3)) {
      wx.showToast({
        title: '经纬度不能为空',
        image: '../../images/error.png',
        duration: 2000,
        mask: true
      })
      return false;
    }
    if (reportType == 3) {
      faultDescription = this.data.pdxItems.find(item => item.checked)?.value || "控制箱故障"
    }
    // if (powerUnit == '') {
    //   wx.showToast({
    //     title: '单位不能为空',
    //     image: '../../images/error.png',
    //     duration: 2000,
    //     mask: true
    //   })
    //   return false;
    // }
    if (faultDescription.length == 0 && !remark) {
      wx.showToast({
        title: '请选择故障描述',
        image: '../../images/error.png',
        duration: 2000,
        mask: true
      })
      return false;
    }
    if (name == '') {
      wx.showToast({
        title: '请输入您的名字',
        image: '../../images/error.png',
        duration: 2000,
        mask: true
      })
      return false;
    }
    var preg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    var greg = /^(0\d{2,3}-\d{7,8})$/;
    if (phone == '') {
      wx.showToast({
        title: '请输入您的联系电话',
        image: '../../images/error.png',
        duration: 2000,
        mask: true
      })
      return false;
    }
    // if((!preg.test(phone) || phone.length!=11) && !greg.test(phone) && phone != ''){
    //   wx.showToast({
    //     title: '电话格式不正确',
    //     image: '../../images/error.png',
    //     duration: 2000,
    //     mask: true
    //   })
    //   return false;
    // }
    if (phone.length < 8) {
      wx.showToast({
        title: '电话格式不正确',
        image: '../../images/error.png',
        duration: 2000,
        mask: true
      })
      return false;
    }
    if ((reportType == 2 || reportType == 3) && !treamId) {
      wx.showToast({
        title: '请选择班组',
        image: '../../images/error.png',
        duration: 2000,
        mask: true
      })
      return false;
    }

    
    var params = {
      faultDescription: faultDescription,
      facilitiesNo: facilitiesNo,
      streetLampType: streetLampType,
      address: address,
      jwdInfo: jwdInfo,
      // powerUnit:powerUnit,
      name: name,
      phone: phone,
      deptid: that.data.deptid,
      remark: remark,
      imgUrl: that.data.imgUrl.toString(),
      streetLampId: that.data.streetLampId,
      type: 1,
      reportType,
    }
    if (reportType == 3) {
      params.distributionBoxid = pdxobj.id;
      params.address = pdxobj.name;
      params.treamId = treamId;
    }
    if (reportType == 2) {
      params.treamId = treamId;
      params.complainantUserName = complainantUserName;
      params.complainantUserPhone = complainantUserPhone;
      if (this.data.dataSourceList.includes(dataSource)) {
        params.dataSource = dataSource;
      } else {
        params.dataSource = `其他-${dataSource}`
      }
      if (dataSource == '12345' || dataSource == '住建工单' || dataSource == '95598' || dataSource == '城市交办函') {
        const {
          returnTime,
          returnDate,
          makeTime,
          makeDate
        } = that.data;
        params.returnTime = `${returnDate} ${returnTime}`;
        params.makeTime = `${makeDate} ${makeTime}`;
      }
      console.log(params)
    }

    console.log(params)

    this.getReportList().then(res => {
      if(res) {
        that.setData({
          loading: true
        });
        var header = {
          'content-type': 'application/x-www-form-urlencoded'
        }
        var encodingStr = app.ecbEncrypto(params)
        wx.request({
          url: app.url + '/web/exceptionReport/add.htm',
          data: encodingStr,
          method: 'POST',
          type: 'json',
          success: function (res) {
            var decodingStr = app.ecbDecrypto(res.data);
            var rest = JSON.parse(decodingStr);
            console.log(rest)
            that.setData({
              loading: false
            });
            if (rest.isSuccess == 0) {
              // wx.showModal({
              //   title: '',
              //   content:"您的问题已上报至花都路灯管理所，我们会尽快安排处理，谢谢！",
              //   showCancel:false,
              //   success: function () {
              //     if (that.data.hasScene){
              //       wx.reLaunch({ url: '../about/about?id=' + that.data.streetLampId })
              //     }else{
              //       wx.switchTab({
              //         url: '../control/controlBooth',
              //       })
              //     }
              //   }
              // })
              wx.showToast({
                title: '上报成功',
                icon: 'success',
                duration: 1000
              })
              setTimeout(function () {
                //要延时执行的代码
                // if (that.data.hasScene){
                //   wx.reLaunch({ url: '../about/about?id=' + that.data.streetLampId })
                // }else{
                //   wx.switchTab({
                //     url: '../control/controlBooth',
                //   })
                // }     
                wx.navigateBack()
              }, 1000) //延迟时间
            } else {
              that.setData({
                loading: false
              });
              wx.showToast({
                title: '故障上报失败',
                image: '../../images/error.png',
                duration: 2000
              })
            }
          }
        })
      }
    })
    
  },

   // N089新华街东镜村华兴工业区
  async getReportList() {
    const { tabIndex, address, pdxName } = this.data;
    const params = {
      pageSize: 3,
      pageNumber: 1,
      address: tabIndex == 3 ? pdxName : address
    };
  
    try {
      // 1. 发起请求
      const res = await new Promise((resolve, reject) => {
        wx.request({
          url: app.url + '/api/account/getSysExceptionReportList.htm',
          data: app.ecbEncrypto(params),
          method: 'POST',
          header: { 'content-type': 'application/x-www-form-urlencoded' },
          success: resolve,
          fail: reject
        });
      });
  
      // 2. 解密数据
      const decodingStr = app.ecbDecrypto(res.data);
      const rest = JSON.parse(decodingStr);
      const list = rest.isSuccess == 0 ? rest.result.content || [] : [];

      console.log(list);
  
      // 3. 如果有数据，显示模态框
      if (list.length > 0) {
        const confirmResult = await new Promise(resolve => {
          wx.showModal({
            title: '',
            content: `当前设备存在已上报的故障，故障原因为 ${list[0].faultDescription}，是否继续上报？`,
            showCancel: true,
            success: res => resolve(res.confirm)
          });
        });
  
        return confirmResult;
      }
  
      return true;
  
    } catch (error) {
      console.error('获取报告列表失败:', error);
      return true;
    }
  },
  clickFun: function (e) {
    var id = e.currentTarget.dataset.id;
    var ob = e.currentTarget.dataset.ob;
    this.setData({
      radioVal: id,
      exobj: ob
    });
  },
  clickFunPdx: function (e) {
    var id = e.currentTarget.dataset.id;
    var ob = e.currentTarget.dataset.ob;
    this.setData({
      radioValPdx: id,
      pdxobj: ob
    });
  },
  sureButton: function () {
    var that = this;
    that.setData({
      moreChflag: true,
      facilitiesNo: that.data.exobj.meterAddr,
      address: that.data.exobj.address,
      jwdInfo: that.data.exobj.lngLat,
      deptid: that.data.exobj.deptid,
      streetLampType: that.data.exobj.streetLampType, //路灯类型
      // powerUnit: that.data.exobj.powerUnit,//权属单位
      streetLampId: that.data.exobj.id,
      deptPhone: that.data.exobj.deptPhone,
      liveArea: that.data.exobj.liveArea
    });
  },
  sureButtonPdx() {
    this.setData({
      pdxName: this.data.pdxobj.name,
      jwdInfo: this.data.pdxobj.lngLat,
      pdxDialog: true,
    })
  },
  hideMoreCh: function () {
    this.setData({
      moreChflag: true
    })
  },
  mapshow: function () {
    this.setData({
      mapshow: !this.data.mapshow
    })
  },
  openMap: function (event) {
    var that = this
    // if (this.data.jwdInfo!=""){
    //   that.setData({
    //     longitude: parseFloat(this.data.jwdInfo.split(',')[0]),
    //     latitude: parseFloat(this.data.jwdInfo.split(',')[1])
    //   })

    // wx.navigateTo({
    //   url: '../control/query?latitude=' + that.data.latitude + '&longitude=' + that.data.longitude,
    // })
    // }   
    console.log(1111)
    wx.chooseLocation({
      success(res) {
        console.log(res)
        that.setData({
          liveArea: res.address,
          address: res.address,
          jwdInfo: `${res.longitude},${res.latitude}`
        })
      },
      fail(res) {
        console.log(res)
      }
    })
  },
  chooseImage(e) {
    var that = this;
    var header = {
      'content-type': 'application/x-www-form-urlencoded',
      'Accept-Encoding': 'gzip, deflate',
      'Accept-Language': 'zh-CN,zh; q=0.8',
      'Accept': '*/*',
      'Cache-Control': 'no-cache',
      'Connection': 'keep-alive',
      'Content-Length': '64',
      'Pragma': 'no-cache',
    };
    wx.chooseImage({
      success(res) {
        const tempFilePaths = res.tempFilePaths;

        tempFilePaths.forEach((item, index) => {
          if (index < 5) {
            wx.uploadFile({
              url: app.url + '/api/account/wxupload.htm',
              filePath: item,
              name: 'file',
              formData: {
                'user': 'test'
              },
              success(res) {
                console.log(res.data)
                var imgUrlList = that.data.imgUrl
                imgUrlList = imgUrlList.concat([res.data])

                var imgshowList = that.data.imgshow;
                imgshowList = imgshowList.concat([item])

                that.setData({
                  imgUrl: imgUrlList,
                  imgshow: imgshowList,
                })
              }
            })
          }

        })

        console.log(tempFilePaths);



      }
    })
  },
  callPhone() {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.deptPhone,
    })
  },
  changeTab(e) {
    var index = e.currentTarget.dataset.index;
    this.setData({
      tabIndex: index
    })
  },
  deleteImg(e) {
    var index = e.currentTarget.dataset.index;
    var imgUrlList = this.data.imgUrl
    var imgshowList = this.data.imgshow;
    imgUrlList.splice(index, 1)
    imgshowList.splice(index, 1)
    this.setData({
      imgUrl: imgUrlList,
      imgshow: imgshowList,
    })
  },
  bindDateChange: function (e) {
    const key = e.currentTarget.dataset.key
    this.setData({
      [key]: e.detail.value
    })
  },
})